using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Module.LinkSite.Library.Data;
using NCS.Module.LinkSite.Library.DataAccess;
using NCS.Library;
using System.Net;
using System.IO;
using NCS.Library.Components;
using NCS.Library.Utilities;
namespace NCS.Module.LinkSite.Web
{
    public partial class ListSupport : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                showListbyActive();
            }
        }
        
        //DataCaching datacache = new DataCaching();

        void showListbyActive()
        {
            DataTable dt = Live_SupporDB.getAllByActive(Convert.ToInt32(AppEnv.PortalId()), AppEnv.GetLanguage());
            rptListSupport.DataSource = dt;
            rptListSupport.DataBind();
        }

        protected void rptListSupport_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                DataRowView row = (DataRowView)e.Item.DataItem;

                Image img = (Image)e.Item.FindControl("img");

                /*object mkobj = datacache.GetHashCache("support_online", row["Name"].ToString());
                if (mkobj != null)
                {
                    int mk = ConvertUtility.ToInt32(mkobj);
                    img.ImageUrl = mk == 334 ? "/images/HomePage/online1.jpg" : "/images/HomePage/online2.jpg";
                    img.AlternateText = mk.ToString();
                }
                else
                {*/
                    System.Net.WebRequest req = System.Net.WebRequest.Create("http://mail.opi.yahoo.com/online?u=" + row["Name"].ToString() + "&t=1&m=g");
                    req.Credentials = CredentialCache.DefaultCredentials;
                    System.Net.WebResponse rsp = req.GetResponse();

                    Stream dataStream = rsp.GetResponseStream();
                    StreamReader reader = new StreamReader(dataStream);
                    int len = reader.ReadToEnd().Length;
                    img.ImageUrl = len == 334 ? "/images/HomePage/online1.jpg" : "/images/HomePage/online2.jpg";
                    img.AlternateText = len.ToString();
                    rsp.Close();
                    //datacache.SetHashCache("support_online", row["Name"], 3, len);
                //}
            }
        }
    }
}